package com.idstaa;

import com.idstaa.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

public class WatchThreadConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        while (true) {
            for (int i = 0; i < 20; i++) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String msg1 = service.sayHello("world");
                        System.out.println(msg1);
                        String msg2 = service.sayGood("world");
                        System.out.println(msg2);
                        String msg3 = service.sayOk("world");
                        System.out.println(msg3);
                    }
                }).start();
            }
            break;
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.idstaa.bean")
    @EnableDubbo
    static class ConsumerConfiguration {
    }
}
